#!/bin/bash
  
f="/root/ip_list"

read -p "input ip prefix(e.g 192.168.1):" ip_prefix #ip地址前缀，例如192.168.1

read -p "input start ip(e.g 1):" ip_start #ping测试开始的ip

read -p "input end ip(e.g 254):" ip_end #ping测试结尾的ip

for i in $(seq ${ip_start} ${ip_end})

do

echo "${ip_prefix}.$i" >> $f #生成ip列表

done

for j in $(cat $f)

do

chk=$(ping -c2 -w2 $j |grep -i "ttl=") #逐个ping

if [ ! -z "${chk}" ];then

echo "$j ok!"

fi

done

rm -rf $f

echo "done!"
